perf(db): reduce read/write fanout across hot paths#4704
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Cuts client polling/invalidation frequency. Logs list/dashboard live refresh moves from 3s to 10s (detail stays 3s only for running/pending), table SSE dispatch invalidations are debounced, subscription invalidations are narrowed to Tightens and batches server-side writes. MCP lifecycle updates collapse select-then-update into single guarded updates (including server/tool scoping), workspace env credential membership sync is batched via Reviewed by Cursor Bugbot for commit 3cf4f7d. Configure here. |
Greptile SummaryThis PR applies a broad performance sweep across hot paths: narrowing query projections (JSONB columns and
Confidence Score: 5/5Safe to merge — all hot-path optimisations are logically equivalent to the code they replace, workspace guards are preserved or tightened, and the migration targets tables small enough that lock windows are negligible. The batched credential writes and ON CONFLICT logic match the old per-row loop behaviour. The MCP UPDATE/DELETE collapses include the workspace predicate directly in the WHERE clause and, for the tool update, actually close an old gap where the bare UPDATE had no serverId check. The React Query staleTime bump is paired with explicit invalidation on every mutating operation. No data loss or correctness regression identified. No files require special attention beyond the minor JSDoc discrepancy in subscription.ts. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Workflow Run / Wand / UsageIndicator socket] -->|invalidateQueries| B[subscriptionKeys.users]
B --> C[useSubscriptionData\nstaleTime=5min]
C --> D[GET /api/billing user]
E[SSE dispatch event] -->|scheduleDispatchInvalidate\n250ms debounce| F[tableKeys.activeDispatches]
F --> G[refetch activeDispatches]
H[Logs page live mode] -->|refetchInterval 10s| I[logsQuery + dashboardStatsQuery]
J[PATCH /api/webhooks/:id] --> K{setClause empty?}
K -->|yes| L[return 200 no-op]
K -->|no| M[UPDATE webhook]
N[markWebhookSuccess] --> O{failedCount already 0?}
O -->|yes, skip| P[no UPDATE]
O -->|no| Q[UPDATE failedCount=0]
R[ensureWorkspaceCredentialMemberships] --> S[SELECT existing revoked]
S --> T[filter out revoked users]
T --> U[batch INSERT ON CONFLICT DO UPDATE\npreserve joinedAt via COALESCE]
V[syncWorkspaceEnvCredentials /\ncreateWorkspaceEnvCredentials] --> W[batch INSERT credentials\nON CONFLICT DO NOTHING]
W --> X[batch INSERT memberships\nON CONFLICT DO NOTHING]
Reviews (3): Last reviewed commit: "fix(webhooks): include NULL failedCount ..." | Re-trigger Greptile |
…, chatDeploy projection, sql newline)
|
Thanks for the review. Addressed in 4baad33:
|
|
@greptile |
|
@cursor review |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3cf4f7d. Configure here.
Summary
subscriptionKeys.all→users()invalidations on workflow run / wand / usage-indicator paths; bumpuseSubscriptionDatastaleTime 30s → 5min; bump usage-indicator socket debounce 1s → 5srefetchOnMount: 'always'fromuseDeploymentInfo(defeated 30s staleTime; rely on post-deploy invalidation)tableKeys.activeDispatchesSSE invalidationsmarkWebhookSuccessguarded withWHERE failed_count <> 0; webhook PATCH skips no-op writesON CONFLICT DO UPDATE/DO NOTHING; remove unusedgetPostgresErrorCodehelper.returning()on table row DELETE and copilotgetRunSegment0211_breezy_cloak:chat(workflow_id, archived_at), two onwebhook, one onworkflow_schedule.workflow_execution_logsindexes deliberately deferred to a concurrent-safe deploy (116 GB table)Type of Change
Checklist